package com.tsu.mall.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tsu.mall.admin.entity.Attendant;
import com.tsu.mall.admin.entity.Waresclassify;
import com.tsu.mall.admin.exception.BusinessException;
import com.tsu.mall.admin.mapper.WaresclassifyMapper;
import com.tsu.mall.admin.service.IWaresclassifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tsu.mall.common.VO.LayuiTableVO;
import com.tsu.mall.common.VO.ResultVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tttttt
 * @since 2023-03-17
 */
@Service
public class WaresclassifyServiceImpl extends ServiceImpl<WaresclassifyMapper, Waresclassify> implements IWaresclassifyService {

    @Override
    public LayuiTableVO doList(String keyword) {
        List<Waresclassify> list=baseMapper.doSelectListPage(keyword);
        LayuiTableVO vo = new LayuiTableVO();
        vo.setData(list);
        return vo;
    }

    @Override
    public ResultVO doDelete(Integer id) {
        ResultVO vo = new ResultVO();
        //id参数是要删除的菜单id
        //查看此菜单是否有子菜单
        List<Waresclassify> list=baseMapper.selectByParentId(id);
        if(list.size() > 0){//有-不删除-错误提示
            throw new BusinessException("存在子菜单，不可以删除！");
        }else {//没有-删除
            baseMapper.deleteById(id);
            vo.setMsg("删除菜单信息成功!");
            return vo;
        }
    }

}
